# -*- coding: utf-8 -*-
import unittest
import os, sys
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parentdir)
from api.base_api.base_api import BaseApi
from api.base_api.find_password import FindPassword
from api.base_api.register import RegisterApi
from api.base_api.login_api import LoginApi
class FindPasswordTest(BaseApi):
    ''' 测试找回密码 '''

    def setUp(self):
        self.mobile = '13900000000'
        self.password = '123abc'
        self.find_password_url = "http://192.168.1.141:8001/find-password"

    def test_user_find_password_success(self):
        ''' 修改成功 '''
        verify_code = RegisterApi().get_user_verify_code(self.mobile)
        payload = FindPassword().find_password(self.mobile, verify_code, self.password)
        response = self.post(self.find_password_url, payload)
        self.assertEqual(response.status_code, 200)
        #新密码登录
        success_status_code = LoginApi().login(self.mobile, self.password).status_code
        self.assertEqual(success_status_code, 200)

    def test_user_find_password_verify_code_fail(self):
        '''短信验证码错误'''
        payload = FindPassword().find_password(self.mobile, 'kkkk', self.password)
        response = self.post(self.find_password_url, payload)
        message = response.json()['message']
        self.assertEqual(response.status_code, 400)
        self.assertEqual(message, '对不起，短信验证码错误或已过期，请重新输入')

if __name__ == '__main__':

    unittest.main()
